#pragma once
#include "win32Container.h"
#include "Shader.h"
#include "Camera.h"
#include "Mesh.h"
class dx11App:win32Container
{
public:
	virtual int MsgLoop();
	virtual void Update();
	virtual void Draw();
public:
	dx11App(
		HINSTANCE hInstance,
		const wstring WndClassName,
		int ShowWnd,
		int width,
		int height,
		bool windowed) :
		win32Container(
			hInstance,
			WndClassName,
			ShowWnd,
			width,
			height,
			windowed)
	{ }
	bool InitializeDirect3d11App();
protected:
	bool EnumerateAdapter();
	bool InitializeDeviceAndSwapChain();
	bool InitializeRenderTargetView();
	bool InitializeDepthStencilView();
	bool InitializeShaderResourceView();
	bool InitD2D_D3D101_DWrite();
	bool InitD2DScreenTexture();
	bool InitializeShaders();
	bool InitialzeConstantBuffer();
	bool InitializeBlendState();
	bool InitialzeRasterizerState();
	bool InitializeLight();
	bool InitializeSampler();
	bool InitDirectInput();
	bool InitScene();
protected:
	void DetectInput();
	void RenderText(const wstring& text, int fps = -1);
public:
	int indexNum;
	Camera camera;
	Timer timer;
public:
	HRESULT hr;
	ComPtr<IDXGIAdapter1> Adapter;
	ComPtr<ID3D11Device> d3d11Device;
	ComPtr<ID3D11DeviceContext> d3d11DevCon;
	ComPtr<IDXGISwapChain> SwapChain;
	const int SwapChainBufferCnt = 1;
public:
	ComPtr<ID3D11RenderTargetView> RenderTargetView;
	ComPtr<ID3D11DepthStencilView> DepthStencilView;
	ComPtr<ID3D11Texture2D> DepthBuffer;
	ComPtr<ID3D11ShaderResourceView> ShaderResourceView;
public:
	Light light;
	cbPerObjectType cbPerObjectVar;
	cbPerFrameType cbPerFrameVar;
public:
	VertexShader VS;
	PixelShader PS;
	PixelShader D2DPS;
	VertexShader SkyMapVS;
	PixelShader SkyMapPS;
public:
	ComPtr<ID3D11Buffer> cbPerObjectBuffer;
	ComPtr<ID3D11Buffer> cbPerFrameBuffer;
	ComPtr<ID3D11Buffer> IndexBuffer;
	ComPtr<ID3D11Buffer> VertexBuffer;
	ComPtr<ID3D11InputLayout> vertLayout;
public:
	ComPtr<ID3D11RasterizerState> WireFrame;
	ComPtr<ID3D11SamplerState> CubesTexSamplerState;
	ComPtr<ID3D11DepthStencilState> DepthStencilState;
	ComPtr<ID3D11BlendState> Transparency;
	ComPtr<ID3D11BlendState> d2dTransparency;
	ComPtr<ID3D11RasterizerState> CCWcullMode;
	ComPtr<ID3D11RasterizerState> CWcullMode;
	ComPtr<ID3D11RasterizerState> DefaultRS;
public:
	ComPtr<ID3D10Device1> d3d10Device_1;
	ComPtr<IDXGIKeyedMutex> keyedMutex11;
	ComPtr<IDXGIKeyedMutex> keyedMutex10;
	ComPtr<ID2D1RenderTarget> D2DRenderTarget;
	ComPtr<ID2D1SolidColorBrush> Brush;
	ComPtr<ID3D11Texture2D> BackBuffer11;
	ComPtr<ID3D11Texture2D> sharedTex11;
	ComPtr<ID3D11Buffer> d2dVertBuffer;
	ComPtr<ID3D11Buffer> d2dIndexBuffer;
	ComPtr<ID3D11ShaderResourceView> d2dTexture;
	ComPtr<IDWriteFactory> DWriteFactory;
	ComPtr<IDWriteTextFormat> TextFormat;
public:
	ComPtr<IDirectInputDevice8> DIKeyboard;
	ComPtr<IDirectInputDevice8> DIMouse;
	DIMOUSESTATE mouseLastState;
	LPDIRECTINPUT8 DirectInput;
};